<template>
    <div class="bigBox">
      <div class="searchBox">
        <div class="zuo">
          <span>
            统计时间：   
          </span>
          <el-date-picker
            size="small"
            v-model="searchDate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy - MM - dd"
            value-format="yyyy-MM-dd"
          >
        </el-date-picker>
      </div>
      <div class="you">
        <div @click="searchTimeCheck(0)" class="days" :class="{border : is_border == 0}">今</div>
        <div @click="searchTimeCheck(1)" class="days" :class="{border : is_border == 1}">昨</div>
        <div @click="searchTimeCheck(2)" class="days" :class="{border : is_border == 2}">近7天</div>
        <div @click="searchTimeCheck(3)" class="days" :class="{border : is_border == 3}">近30天</div>
      </div>
      <div class="btns">
        <el-button class="search" @click="search">查询</el-button>
        <el-button class="reset">重置</el-button>
      </div>
      </div>
      <div class="bg">
        <div class="topBox">
          <div class="top_box_item" v-for="(item,index) in topList" :key="index">
            <div class="top_box_data">
              <div class="data_top">{{ item.data }}</div>
                    <div class="data_bottom">{{ item.title }}</div>
                </div>
                <div class="icon">
                  <img :src="item.url" alt="充电总量">
                </div>
            </div>
          </div>
        <div class="eCharts">
            <div id="chongdianliang" style="width:450px;height: 367.99px;">1111</div>
            <div id="chargeCount" style="width:450px;height: 367.99px;"></div>
            <div id="chargeFee" style="width:450px;height: 367.99px;"></div>
            <div id="Fonctionnement" style="width:450px;height: 367.99px;"></div>
            <div id="chargeMoney" style="width:450px;height: 367.99px;"></div>
            <div id="prepare" style="width:450px;height: 367.99px;"></div>
          </div>
        </div>
      </div>
</template>

<script>
    export default {
        data() {
            return {
              searchDate:'',
              is_border:-1,
                topList:[
                    {
                        data:15802,
                        title:'充电总量(度)',
                        url:require('@/images/home/total_charging.png')
                    },
                    {
                        data:5081,
                        title:'充电总时长(分钟)',
                        url:require('@/images/home/total_time.png')
                    },
                    {
                        data:15000,
                        title:'充电总次数(次)',
                        url:require('@/images/home/total_count.png')
                    },
                    {
                        data:173,
                        title:'年度累计交易额(万元)',
                        url:require('@/images/home/year_money.png')
                    },
                    {
                        data:14.4,
                        title:'月度累计交易额(万元)',
                        url:require('@/images/home/month_money.png')
                    },
                    {
                        data:0.48,
                        title:'日度累计交易额(万元)',
                        url:require('@/images/home/day_money.png')
                    },
                ]
            }
        },
        mounted() {
            this.dianLiang()
            this.chargeCount()
            this.chargeFee()
            this.Fonctionnement()
            this.chargeMoney()
            this.prepare()
        },
        methods: {
          searchTimeCheck(val){
            this.is_border = val
            if(val == 0){
              const date = new Date();
              let year = date.getFullYear() // 年
              let month = date.getMonth() + 1; // 月
              let day = date.getDate(); // 日
              const start = new Date();
              console.log('今天',[year,month,day].join('-'))
            } else if(val == 1){
              const yesterday = new Date();
              yesterday.setTime(yesterday.getTime() - 3600 * 1000 * 24);
              let yesterday_year = yesterday.getFullYear() // 年
              let yesterday_month = yesterday.getMonth() + 1; // 月
              let yesterday_day = yesterday.getDate(); // 日
              console.log('昨天',[yesterday_year,yesterday_month,yesterday_day].join('-'))
            } else if(val == 2){
              const start = new Date();
              const end = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              let start_year = start.getFullYear() // 年
              let start_month = start.getMonth() + 1; // 月
              let start_day = start.getDate(); // 日
              let end_year = end.getFullYear() // 年
              let end_month = end.getMonth() + 1; // 月
              let end_day = end.getDate(); // 日
              console.log('7天前',[start_year,start_month,start_day].join('-'))
              console.log('到今天',[end_year,end_month,end_day].join('-'))
            } else{
              const start = new Date();
              const end = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 29);
              let start_year = start.getFullYear() // 年
              let start_month = start.getMonth() + 1; // 月
              let start_day = start.getDate(); // 日
              let end_year = end.getFullYear() // 年
              let end_month = end.getMonth() + 1; // 月
              let end_day = end.getDate(); // 日
              console.log('30天前',[start_year,start_month,start_day].join('-'))
              console.log('到今天',[end_year,end_month,end_day].join('-'))
            }
          },
          search(){
            
          },
            dianLiang(){
            var myChart = this.$echarts.init(document.getElementById("chongdianliang"));
            myChart.setOption({
              title:{
                text:'充电量概况'
              },
              tooltip:{},
              xAxis:{
                type:'category',
                data:['1','2','3','4','5','6','7']
              },
              yAxis:{},
              series:[
                {
                name:"销量",
                type:'line',
                areaStyle: {
                  color: {
                    type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 2,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#c8d3fc' // 0%处的颜色为红色
                        }, {
                            offset: 0.5,
                            color: '#fefeff' // 100%处的颜色为蓝
                        }]
                  },
                  opacity: 0.5
                },
                smooth: true,
                data:[100,400,200,300,500,400,300],
                 itemStyle: {
                    color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 5,
                        colorStops: [{
                            offset: 0,
                            color: '#335BF5' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#335BF5' // 100%处的颜色为蓝
                        }]
                    }
                 }
              }
              ]
            })
          },
          chargeCount(){
            var myChart = this.$echarts.init(document.getElementById("chargeCount"));
            myChart.setOption({
              title:{
                text:'充电次数概况'
              },
              tooltip:{},
              xAxis:{
                type:'category',
                data:['1','2','3','4','5','6','7']
              },
              yAxis:{},
        
              color:['#335bf5'],
              series:[
                {
                name:"销量",
                type:'bar',
                data:[100,200,300,400,500,500,300],
                itemStyle: {
                  barBorderRadius:[30, 30, 0, 0],
                  color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#355cf5' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#f2f5fe' // 100%处的颜色为蓝
                        }]
                    },
                }
              },
             
              ]
            })
          },
          // 柱状加折线
          chargeFee(){
            var myChart = this.$echarts.init(document.getElementById("chargeFee"));
            myChart.setOption({
              legend:{
                right: "15%", //右侧
                selectedMode: 'single',
                data:['总发行量','已领取','未使用','已使用','已过期'],
                icon: "roundRect",
                 textStyle: {
                      color: '#ccc'
                  },
                  itemWidth:40, 
                  itemHeight:20,
              },
              title:{
                text:'充电费用概况'
              },
              tooltip:{},
              xAxis:{
                type:'category',
                data:['1','2','3','4','5','6','7'],
                textStyle: {
                    color: '#949BBE'//修改坐标轴字体颜色
                },
                fontSize:14//调整坐标轴字体大小
              },
              yAxis:{
              },
              color:['#335bf5'],
              series:[
                {
                name:"销量",
                type:'bar',
                data:[100,155,204,304,402],
                itemStyle: {
                  barBorderRadius:[30, 30, 0, 0],
                  color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#56c521' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#f4fbf0' // 100%处的颜色为蓝
                        }]
                    },
              },
          
              },
                {
                name:"销量",
                type:'line',
                smooth: true,
                data:[220,236,541,522,510,450,300],
                itemStyle: {
                  color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 2,
                        colorStops: [{
                            offset: 0,
                            color: '#5A89FF' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#5A89FF' // 100%处的颜色为蓝
                        }]
                    },
              },
              },
                {
                name:"销量",
                type:'line',
                smooth: true,
                data:[100,200,300,400,500,500,400],
                itemStyle: {
                  color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#FCB178' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#FCB178' // 100%处的颜色为蓝
                        }]
                    },
              },
              },
              ]
            })
          },
          // 饼状图
          Fonctionnement(){
            var myChart = this.$echarts.init(document.getElementById("Fonctionnement"));
            myChart.setOption({
              title:{
                text:'设备运营'
              },
              tooltip:{},
              color:['#03e38a', '#3850ff', '#7c8dff','#ffe688','#9ffe85','#9ffe85'],
              series:[
              {
                type: 'pie',
                roseType :'area',
                data: [
                  {
                    value: 20,
                    name: '充电中',
                    color:"#03e38a"
                  },
                  {
                    value: 50,
                    name: '空闲中'
                  },
                  {
                    value: 30,
                    name: '预约中'
                  },
                  {
                    value: 10,
                    name: '故障中'
                  },
                  {
                    value: 50,
                    name: '已充满'
                  }
                ],
                radius: ['40%', '60%']
              },
              ]
            })
          },
          chargeMoney(){
            var myChart = this.$echarts.init(document.getElementById("chargeMoney"));
            myChart.setOption({
              title:{
                text:'充电金额情况'
              },
              tooltip:{},
              xAxis:{
                type:'category',
                data:['1','2','3','4','5','6','7']
              },
              yAxis:{},
              color:['#335bf5'],
              series:[
                {
                name:"销量",
                type:'line',
                areaStyle: {
                  color: {
                    type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 2,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#c8d3fc' // 0%处的颜色为红色
                        }, {
                            offset: 0.5,
                            color: '#fefeff' // 100%处的颜色为蓝
                        }]
                  },
                  opacity: 0.5
                },
                smooth: true,
                data:[100,400,200,300,500],
                 itemStyle: {
                    color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 5,
                        colorStops: [{
                            offset: 0,
                            color: '#8062FE' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#335BF5' // 100%处的颜色为蓝
                        }]
                    }
                 }
              }
              ]
            })
          },
          prepare(){
            var myChart = this.$echarts.init(document.getElementById("prepare"));
            myChart.setOption({
              title:{
                text:'预约情况'
              },
              tooltip:{},
              xAxis:{
                type:'category',
                data:['1','2','3','4','5','6','7']
              },
              yAxis:{},
              color:['#335bf5'],
              series:[
                {
                name:"取消预约",
                type:'line',
                smooth: true,
                data:[200,100,300,430,200,530,300],
                color:'#F56C6C',
                itemStyle:{
                  normal:{
                      lineStyle:{
                          width:2,
                          type:'dashed'  //'dotted'虚线 'solid'实线
                      }
                  }
                }
              },
              {
                name:"预约充电",
                type:'line',
                smooth: true,
                data:[50,500,440,80,200,250,200],
                color:'#2DC48D',
               
              },
                {
                name:"总预约",
                type:'bar',
                data:[100,200,300,400,500,300,200,300],
                itemStyle: {
                  barBorderRadius:[30, 30, 0, 0],
                  color: {
                        type: 'linear', // 线性渐变
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0,
                            color: '#766AFF' // 0%处的颜色为红色
                        }, {
                            offset: 1,
                            color: '#FFFFFF' // 100%处的颜色为蓝
                        }]
                    },
              },
                },
              ]
            })
          },
        },
    }
</script>

<style lang="less" scoped>
.eCharts{
  margin-top: 32px;
}
.eCharts>div{
  background: white;
  padding-top: 24px;
  padding-left: 16px;
  margin-bottom: 32px;
  border-radius: 6px 6px 6px 6px;
}
.bg{
  overflow: hidden;
  background: #f8fafe !important;
}
.topBox{
  margin-top: 32px;
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 100.03px;
}
.top_box_item{
    flex: 1;
    position: relative;
    padding-left:16.03px;
    padding-right: 16.03px;
    padding-bottom: 25.97px;
    background: #FFFFFF;
    border-radius: 6.02px 6.02px 6.02px 6.02px;
    margin-right: 16.03px;
    opacity: 1;
    flex-wrap: nowrap;
    min-width: 188.02px;
    min-height:100.03px ;
}
.top_box_item:last-child{
    margin-right: 0px;
}

.icon{
    float: right;
    margin-top: 24.99px;
    margin-right: 7.98px;
    width: 49.98px;
    height: 49.98px;
    background: #EDF3FF;
    border-radius: 49.98px;
    line-height: 49.98px;
    opacity: 1;
}
.icon img{
    width: 25.97px;
    height: 25.97px;
    vertical-align: middle;
}
.top_box_data{
    float: left;
    margin-left: 16.03px;
    margin-top: 28px;
}
.data_top{
    height: 24.01px;
    font-size: 24.01px;
    text-align: left;
    font-family: PingFang SC-Semibold, PingFang SC;
    font-weight: 600;
    color: #000000;
    line-height: 24.01px;
}
.data_bottom{
    margin-top: 10.01px;
    height: 11.97px;
    font-size: 11.97px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #949BBE;
    line-height: 11.97px;
}
.eCharts{
    width: 100%;
    padding-left: 16.03px;
    padding-right: 16.03px;
    padding-top:31.99px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
}
.eCharts>div{
    margin-right: 16.03px;
    width: 578.97px;
    height: 578.97px;
}
.searchBox{
  width: 100%;
  height: 84px;
  text-align: left;
  line-height: 84px;
  margin-bottom: 31.99px;
  background: #FFFFFF;
  border-radius: 6.02px 6.02px 6.02px 6.02px;
  opacity: 1;
}
.searchBox span{
  display: inline-block;
  text-indent: 16.03px;
}
.el-date-picker{
  height: 35.98px;
  float: left;
}
.days{
  display: inline-block;
  height: 35.98px;
  padding-left: 11.97px;
  padding-right: 11.97px;
  line-height: 35.98px;
  background: #F6F7FB;
  border-radius: 3.99px 3.99px 3.99px 3.99px;
  opacity: 1;
  margin-right: 11.97px;
  cursor: pointer;
}
.days:first-child{
  margin-left: 24.01px;
}
.zuo{
  float: left;
}
.you{
  float: left;
}
.border{
  border: .98px solid #1989FA;
}
.btns{
  float: right;
  margin-right: 16.03px;
}
.search{
  background: #165BFF;
  color: white;
  border: 0;
}
.reset{
  background: #edf0f6;
  border: 0;
  color: #666666;
}
.bigBox{
  text-align: center;
}
</style>
<style>
.el-range-input{
    background: #f0f1f6;
    font-size: .171rem !important;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
}
</style>